

// 即就是对ISplit的多态的 封装，封装成统一的创造接口
// ，可以设想先有了ISplit及其子类，如何再 才能做一个统一的创造接口
class ISplit {
 public:
  ISplit() {}
  virtual ~ISplit() {}

  virtual void SplitFunc() = 0;
};

//具体类
class BinarySplit : public ISplit {
 public:
  void SplitFunc() { printf("This is BinarySplit\n"); }
};

class TxtSplit : public ISplit {
 public:
  void SplitFunc() { printf("This is TxtSplit\n"); }
};

class ISplitFactory {
 public:
  ISplitFactory() {}
  virtual ~ISplitFactory() {}

  virtual ISplit* CreateSplitter() = 0;
};

//具体工厂
class BinarySplitFactory : public ISplitFactory {
 public:
  ISplit* CreateSplitter() { return new BinarySplit(); }
};

class TxtSplitFactory : public ISplitFactory {
 public:
  ISplit* CreateSplitter() { return new TxtSplit(); }
};  

class MainForm {
 public:
  ISplitFactory* splitFactory;
  MainForm(ISplitFactory* splitFactory) { this->splitFactory = splitFactory; }
  void Btn1Click() {
    ISplit* splitter =
        splitFactory->CreateSplitter();  //通过工厂模式做成了"多态new"
    splitter->SplitFunc();
  }
}
